﻿﻿using System;
using System.Collections.Generic;
using System.Linq;
using Common;
using Core;

namespace Core
{
    public class CategoryRepository : RepositoryBase<Category, int>, ICategoryRepository
    {
        private readonly ICache _Cache;

        public CategoryRepository(IDbContext context, ICache _cache)
            : base(context)
        {
            _Cache = _cache;
        }

        public override IEnumerable<Category> GetAll()
        {
            return _Cache.Get(Settings.CategoryCacheKey, () =>
            {
                var catList = base.GetAll();
                return catList.Where(c => c.IsActive).ToList();
            });
        }

        protected override void SaveChanges()
        {
            Context.SaveChanges();
        }
    }
}